import json

from flask import Flask, render_template, Response, request

from apps.pojo.Entity import db
from apps.service.LoginService import LoginService
from apps.controller.UserController import user_bp

app = Flask(__name__)

app.register_blueprint(user_bp)

# 设计数据库连接

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:283418@localhost:3306/flask'

with app.app_context():
    db.init_app(app)
    #db.drop_all()
    #db.create_all()

@app.route('/')
def tologin():
    return render_template('login.html')

@app.route('/dologin', methods=['POST'])
def dologin():
    param = request.form

    username = param.get('username')
    password = param.get('password')

    result = LoginService.login(username, password)
    if result:
        return render_template('index.html')
    else:
        return render_template('login.html')

@app.route('/index_v1')
def index_v1():
    return render_template('index_v1.html')  # 渲染模板文件


@app.route('/index_v3')
def index_v3():
    return render_template('index_v3.html')

if __name__ == '__main__':
    app.run()